package com.wifi.mydlq.demo.controller;

import com.wifi.mydlq.demo.service.TokenUtilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TokenController {

    @Autowired
    private TokenUtilService tokenUtilService;

    @GetMapping("/token")
    public String getToken() {
        return tokenUtilService.generateToken("tokenTest");
    }

    @PostMapping("/testToken")
    public String testToken(@RequestHeader(value = "token") String token) {
        return tokenUtilService.validToken(token, "tokenTest") ? "正常调用" : "重复调用";
    }
}
